<template>
    <div class="wrapper">
        <h1>computed</h1>
        姓：<input type="text" v-model="firstName"> <br />
        名：<input type="text" v-model="lastName"><br />
        全名：{{ fullName }}
        <button @click="changeFullName">修改全名</button>
    </div>
</template>

<script lang="ts" setup name="Computed">

import { ref, computed } from 'vue'
let firstName = ref('zhang')
let lastName = ref('san')

// 只读
// let fullName = computed(() => {
//     return firstName.value + '-' + lastName.value
// })

// 可写
let fullName = computed({
    get() {
        return firstName.value + '-' + lastName.value
    },
    set(v) {
        firstName.value = v
        lastName.value = v
        // fullName.value = v
    }
})

function changeFullName() {
    fullName.value = '新名字'
}

</script>


<style scoped>
.wrapper {
    background-color: skyblue;
    box-shadow: 0 0 10px;
    border-radius: 10px;
    padding: 20px;
    margin: 20px
}

button {
    margin: 0 5px;
}
</style>